package ntu.metaweb.update;

import java.io.IOException;

import rice.p2p.commonapi.rawserialization.InputBuffer;
import ntu.p2p.dht.messaging.DHTDifferenceDeserializer;
import ntu.p2p.dht.messaging.DHTObjectDifference;

public class MetawebDifferenceDeserializer implements
		DHTDifferenceDeserializer {

	@Override
	public DHTObjectDifference deserialize(InputBuffer buf) {
		try {
			short type = buf.readShort();
			switch (type) {
			case UpdatePageRating.TYPE:
				return UpdatePageRating.build(buf);
			case NewComment.TYPE:
				return NewComment.build(buf);
			case NewTag.TYPE:
				return NewTag.build(buf);
			case UpdatePageTitle.TYPE:
				return UpdatePageTitle.build(buf);
			case UpdateTagRating.TYPE:
				return UpdateTagRating.build(buf);
			case PageAverageRating.TYPE:
				return PageAverageRating.build(buf);
			case UpdateCommentRating.TYPE:
				return UpdateCommentRating.build(buf);
			case UpdateLinkRating.TYPE:
				return UpdateLinkRating.build(buf);
			case NewLink.TYPE:
				return NewLink.build(buf);
			case DeleteTag.TYPE:
				return DeleteTag.build(buf);
			case DeleteLink.TYPE:
				return DeleteLink.build(buf);
			default:
				return null;
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}

}
